package com.yinhai.activity;

import com.androidquery.AQuery;
import com.lz.util.Utils;
import com.yinhai.photo.utils.Photo;
import com.yinhai.util.ByteToString;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.ImageView;

public class MoreAppAdViewImgActivity extends Activity{
	
	private AQuery aq = null ;
	MoreAppAdViewImgActivity thisRef=null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pop_chat_pic);
		aq = new AQuery(this);
		thisRef =this;
	/*	ImageView mLv_pop_rec = (ImageView)findViewById(R.id.chat_img);
		Bitmap bitmap = null;  
        try{  
            // out = new FileOutputStream("/sdcard/aa.jpg");  
            byte[] bitmapArray;  
            bitmapArray = ByteToString.hexStringToByte(getIntent().getStringExtra("pic"));
            bitmap = BitmapFactory.decodeFile(getIntent().getStringExtra("pic").toString());
            mLv_pop_rec.setImageBitmap(zoomImg(bitmap));
            // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);  
        }catch (Exception e){  
        }*/ 
		aq.id(R.id.chat_img).image(getIntent().getStringExtra("pic").toString(),true,true);
		Bitmap preset = aq.getCachedImage(getIntent().getStringExtra("pic").toString());
		Bitmap newPic = Photo.zoomImg(preset, 0, thisRef);
		aq.id(R.id.chat_img).image(newPic);
        //aq.id(R.id.chat_img).image(getIntent().getStringExtra("pic").toString(), true, true);
	}
	
	// 缩放图片
	public Bitmap zoomImg(Bitmap bm){
	   // 获得图片的宽高
	   int width = bm.getWidth();
	   int height = bm.getHeight();
	   
	   DisplayMetrics dm = new DisplayMetrics();
	   dm = this.getApplicationContext().getResources().getDisplayMetrics();
	   
	   int newWidth = dm.widthPixels;
	   // 计算缩放比例
	   float scaleWidth = ((float) newWidth) / width;
	   // 取得想要缩放的matrix参数
	   Matrix matrix = new Matrix();
	   matrix.postScale(scaleWidth, scaleWidth);
	   // 得到新的图片
	   Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
	   return newbm;
	}

}
